package com.cloudfun.campusshare.controller;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.core.collection.CollectionUtil;
import com.cloudfun.campusshare.common.constant.*;
import com.cloudfun.campusshare.common.exception.BusinessException;
import com.cloudfun.campusshare.common.model.dto.OrderInfoImportDTO;
import com.cloudfun.campusshare.common.model.vo.*;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.common.response.PageResult;
import com.cloudfun.campusshare.common.security.AuthRequired;
import com.cloudfun.campusshare.common.security.AuthenticationHolder;
import com.cloudfun.campusshare.entity.DeviceEntity;
import com.cloudfun.campusshare.entity.OrderEntity;
import com.cloudfun.campusshare.entity.ProjectEntity;
import com.cloudfun.campusshare.entity.UserEntity;
import com.cloudfun.campusshare.repo.OrderEntityRepo;
import com.cloudfun.campusshare.repo.ProjectEntityRepo;
import com.cloudfun.campusshare.repo.UserEntityRepo;
import com.cloudfun.campusshare.service.DeviceOrderService;
import com.cloudfun.campusshare.service.DeviceService;
import com.cloudfun.campusshare.util.AmountUtil;
import com.cloudfun.campusshare.util.BeanCopyUtil;
import com.cloudfun.campusshare.util.ExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


/**
 * Created by Huqin on 2019/12/11
 */
@Slf4j
@RestController
@RequestMapping("/v1/deviceOrder")
@Api(value = "设备订单信息模块", description = "设备订单信息模块")
@AuthRequired
public class DeviceOrderController {

    @Autowired
    private DeviceOrderService deviceOrderService;

    @Resource
    private UserEntityRepo userEntityRepo;

    @Resource
    private OrderEntityRepo orderEntityRepo;

    @Resource
    private ProjectEntityRepo projectEntityRepo;

    @Autowired
    private DeviceService deviceService;

    @ApiOperation(value = "上传设备订单信息", notes = "上传设备订单信息")
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @AuthRequired(type = TokenType.TOOLKIT)
    BaseResult<?> createDeviceOrder(@ApiParam(value = "deviceOrderVO", required = true) @Valid @RequestBody DeviceOrderVO deviceOrderVO) throws Exception {
        if (StringUtils.isNotBlank(deviceOrderVO.getUserPhone())) {
            Matcher m = Pattern.compile(BaseConstant.PHONE_REGEX_PATTERN).matcher(deviceOrderVO.getUserPhone());
            if (!m.matches()) {
                return BaseResultFactory.produceResult(Code.PARAMETER_ERROR, "手机号错误");
            }
        }
        return deviceOrderService.create(deviceOrderVO);
    }

    @ApiOperation(value = "查询项目订单列表", notes = "查询项目订单列表")
    @GetMapping("/byProject")
    @AuthRequired(role = {RoleType.ADMIN, RoleType.FINANCIAL_INSTITUTIONS, RoleType.OPERATIONAL_MERCHANT})
    BaseResult<PageResult<ProjectDeviceOrderListVO>> queryProjectDeviceOrders(Pageable pageable, String projectId) {
        return BaseResultFactory.produceResult(Code.SUCCESS, deviceOrderService.searchProjectDeviceOrders(projectId, pageable));
    }

    @ApiOperation(value = "导出项目订单列表", notes = "导出项目订单列表")
    @GetMapping("/export/byProject")
    @AuthRequired(role = {RoleType.ADMIN, RoleType.FINANCIAL_INSTITUTIONS, RoleType.OPERATIONAL_MERCHANT})
    BaseResult<?> exportProjectDeviceOrders(HttpServletResponse response, String projectId) throws Exception {
        long start = System.currentTimeMillis();
        List<ProjectDeviceOrderExportVO> exportVOList = deviceOrderService.exportProjectDeviceOrders(projectId);
        log.debug("导出{}个项目订单记录耗时：{}ms", exportVOList.size(), (System.currentTimeMillis() - start));
        ProjectEntity projectEntity = projectEntityRepo.findById(projectId).orElseThrow(() -> new BusinessException(Code.NODATA));
        String projectName = projectEntity.getName();
        String userId = projectEntity.getUserId();
        UserEntity merchant = userEntityRepo.findById(userId).orElseThrow(() -> new BusinessException(Code.NODATA));
        String enterpriseName = merchant.getEnterpriseName();
        ExcelUtils.exportExcel(exportVOList, null, "设备订单信息", ProjectDeviceOrderExportVO.class, enterpriseName + "-" + projectName + "-OrderData", response);
        return BaseResultFactory.produceResult(Code.SUCCESS, "成功");
    }

    @ApiOperation(value = "查询订单列表", notes = "查询订单列表")
    @GetMapping("/list")
    @AuthRequired(role = {RoleType.ADMIN, RoleType.FINANCIAL_INSTITUTIONS, RoleType.OPERATIONAL_MERCHANT,RoleType.REPLENISH})
    BaseResult queryDeviceOrderList(Pageable pageable, String startTime, String endTime, String keyword, String deviceType,
                                    Integer orderStatus, String projectId) {
        OrderStatus orderStatusEnum = null;
        if (null != orderStatus) {
            // TODO orderStatus同步前端改掉
            orderStatusEnum = OrderStatus.getOrderStatusByCode(orderStatus + 1);
        }
        return BaseResultFactory.produceResult(Code.SUCCESS, deviceOrderService.queryDeviceOrderList(pageable, startTime,
                endTime, keyword, deviceType, orderStatusEnum, projectId));
    }

    @ApiOperation(value = "设备订单批量导入", notes = "设备订单批量导入")
    @PostMapping("/batch/import")
    @AuthRequired(role = RoleType.ADMIN)
    public BaseResult orderBatchImport(MultipartFile file) throws Exception {
        if (file.isEmpty()) {
            return BaseResultFactory.produceEmptyResult(Code.ERROR, "文件不能为空");
        }

        ImportParams params = new ImportParams();
        params.setHeadRows(1);
        params.setImportFields(OrderInfoImportDTO.fields);

        List<OrderInfoImportDTO> dataList = ExcelImportUtil.importExcel(file.getInputStream(), OrderInfoImportDTO.class, params);
        if (CollectionUtils.isEmpty(dataList)) {
            return BaseResultFactory.produceEmptyResult(Code.ERROR);
        }

        dataList.stream().filter(this::blankLineFilter).forEach(x -> {
            DeviceEntity device = deviceService.getDeviceWithAuthByImei(x.getImei());
            OrderEntity entity = BeanCopyUtil.copy(x, OrderEntity.class);
            UserEntity user = userEntityRepo.findByEnterpriseName(x.getBorrowerName());
            if (Objects.isNull(user)) {
                throw new BusinessException(Code.ERROR, "该运营商不存在");
            }
            OrderEntity byOrderNo = orderEntityRepo.findByOrderNo(x.getOrderNo());
            if (!Objects.isNull(byOrderNo)) {
                throw new BusinessException(Code.ERROR, "订单号" + x.getOrderNo() + "已存在订单，请不要导入重复订单号");
            }
            entity.setDeviceId(device.getId());
            entity.setCustomerPhone(x.getUser());
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
//            LocalDateTime parse = LocalDateTime.parse(x.getOrderCreateTime(), formatter);
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            Date date;
            try {
                date = sf.parse(x.getOrderCreateTime());
            } catch (ParseException e) {
                throw new BusinessException(Code.ERROR, "请输入yyyy-MM-dd hh:mm:ss的时间格式");
            }
            entity.setTradeTime(String.valueOf(date.getTime()));
            entity.setUserId(user.getId());
            entity.setPrice(AmountUtil.strAmount2Int(x.getActualMoney()));
            entity.setOrderStatus(Optional.ofNullable(OrderStatus.getOrderStatusByMsg(x.getOrderStatus())).orElseThrow(() -> new BusinessException(Code.ERROR, "请填写正确的订单状态")));
            entity.setProjectId(device.getProjectId());
            orderEntityRepo.save(entity);
        });
        return BaseResultFactory.produceEmptyResult(Code.SUCCESS);

    }

    public Boolean blankLineFilter(OrderInfoImportDTO o) {

        return !(StringUtils.isBlank(o.getOrderNo())
                && StringUtils.isBlank(o.getImei())
                && StringUtils.isBlank(o.getOrderCreateTime())
                && StringUtils.isBlank(o.getOrderStatus())
                && StringUtils.isBlank(o.getUser())
                && o.getActualMoney() == null);
    }

    @ApiOperation(value = "用户查询订单列表", notes = "用户查询订单列表")
    @GetMapping("/customer/list")
    @AuthRequired(role = RoleType.CUSTOMER)
    public BaseResult<PageResult<UseOrderListVO>> customerQueryUseRecord(Pageable pageable) {
        PageResult<UseOrderListVO> pg = deviceOrderService.searchUserOrder(pageable);
        return BaseResultFactory.produceResult(Code.SUCCESS, pg);
    }

    @ApiOperation(value = "用户查询订单详情", notes = "用户查询订单详情")
    @GetMapping("/customer/detail/{orderId}")
    @AuthRequired(role = RoleType.CUSTOMER)
    public BaseResult<UseOrderDetailVO> customerUserRecordDetail(@PathVariable String orderId) {
        return BaseResultFactory.produceResult(Code.SUCCESS, deviceOrderService.queryUseDetail(orderId));
    }

    @ApiOperation(value = "用户进行中订单列表", notes = "用户进行中订单列表")
    @GetMapping("/executing/list")
    @AuthRequired(role = RoleType.CUSTOMER)
    public BaseResult executingOrderQuery(Pageable pageable) {
        PageResult pageResult = deviceOrderService.queryExecutingOrderList(pageable);
        return BaseResultFactory.produceResult(Code.SUCCESS, pageResult);
    }

    @ApiOperation(value = "用户订单生成", notes = "用户订单生成")
    @PostMapping("/generate")
    @AuthRequired(role = RoleType.CUSTOMER)
    public BaseResult generateOrder(@ApiParam(value = "orderGenerateVO", required = true) @RequestBody OrderGenerateVO orderGenerateVO) {
        log.info(orderGenerateVO.toString());
        DeviceEntity device = deviceService.getDeviceWithoutAuthByMachineNo(orderGenerateVO.getMachineNo());
        if (!deviceService.lockDevice(device.getId())) {
            return BaseResultFactory.produceEmptyResult(Code.ERROR, "该设备已被占用");
        }
        try {
            return BaseResultFactory.produceResult(Code.SUCCESS, deviceOrderService.generateOrder(orderGenerateVO));
        } catch (Exception e) {
            //生成订单异常释放锁
            deviceService.unlockDevice(device.getId());
            throw e;
        }
    }

    @ApiOperation(value = "设备是否可用", notes = "设备是否可用")
    @GetMapping("/available")
    @AuthRequired(role = {RoleType.CUSTOMER,RoleType.REPLENISH})
    public BaseResult<?> deviceAvailable(@ApiParam(value = "设备机器码") @RequestParam String machineNo,@ApiParam(value = "是否从预约页面进入")@RequestParam(required = false,defaultValue = "false") boolean isInvokeByOrderPage) {
        DeviceEntity device = deviceService.getDeviceWithoutAuthByMachineNo(machineNo);
        try {
            BaseResult<?> deviceAvailable = deviceOrderService.deviceAvailable(device);
            List<OrderEntity> orderList = orderEntityRepo.findByCustomerIdAndDeviceIdAndOrderStatus(AuthenticationHolder.getUserId(), device.getId(), OrderStatus.IN_ORDER);
            if(isInvokeByOrderPage && CollectionUtil.isEmpty(orderList)){
                return BaseResultFactory.produceEmptyResult(Code.SCAN_WRONG_DEVICE);
            }
            if (deviceAvailable.getCode() == Code.ALREADY_IN_USE.getCode()) {

                return BaseResultFactory.produceResult(Code.ALREADY_IN_USE, switchToOperListVO(orderList));
            }
            if (deviceAvailable.getCode() == Code.HAVE_IN_PROGRESS_ORDER.getCode()) {
                return BaseResultFactory.produceResult(Code.HAVE_IN_PROGRESS_ORDER, switchToOperListVO(orderEntityRepo.findByCustomerIdAndDeviceIdAndOrderStatus(AuthenticationHolder.getUserId(), device.getId(), OrderStatus.IN_PROGRESS)));
            }
            List<OrderEntity> paidOrderList = orderEntityRepo.findByCustomerIdAndDeviceIdAndOrderStatus(AuthenticationHolder.getUserId(), device.getId(), OrderStatus.PAID);
            if(CollectionUtil.isNotEmpty(paidOrderList)){
                return BaseResultFactory.produceResult(Code.SUCCESS,switchToOperListVO(paidOrderList));
            }
            List<OrderEntity> selfClean = orderEntityRepo.findByCustomerIdAndDeviceIdAndOrderStatus(AuthenticationHolder.getUserId(), device.getId(), OrderStatus.SELF_CLEANED);
            if(CollectionUtil.isNotEmpty(selfClean)){
                return BaseResultFactory.produceSuccess(Code.ALREADY_IN_USE);
            }

            if (deviceAvailable.getCode() == Code.DEVICE_NOT_AVAILABLE.getCode()) {
                return deviceAvailable;
            }
            if(deviceAvailable.getCode() == Code.NOT_IN_SERVICE_TIME.getCode()){
                return BaseResultFactory.produceEmptyResult(Code.NOT_IN_SERVICE_TIME);
            }
            if(!isInvokeByOrderPage && deviceAvailable.getCode() == Code.ORDER_DEVICE_COUNT_OVERFLOW.getCode()){
                return BaseResultFactory.produceEmptyResult(Code.ORDER_DEVICE_COUNT_OVERFLOW);
            }
        } catch (BusinessException e) {
            if (Code.HAVE_IN_PROGRESS_ORDER.equals(e.getErrorCode())) {
                List<OrderEntity> process = orderEntityRepo.findByCustomerIdAndDeviceIdAndOrderStatus(AuthenticationHolder.getUserId(), device.getId(), OrderStatus.IN_PROGRESS);
                return BaseResultFactory.produceResult(Code.HAVE_IN_PROGRESS_ORDER, switchToOperListVO(process));
            }
        }

        return BaseResultFactory.produceSuccess();
    }

    private List<DeviceOrderListForOperVO> switchToOperListVO(List<OrderEntity> list) {
        return list.stream().map(x -> {
            DeviceOrderListForOperVO copy = BeanCopyUtil.copy(x, DeviceOrderListForOperVO.class);
            copy.setTradeTime(x.getCreateTime());
            copy.setPrice(AmountUtil.amountRoundStr(x.getPrice(), 2));
            copy.setDiscountPrice(AmountUtil.amountRoundStr(x.getDiscountPrice(), 2));
            copy.setSettlementPrice(AmountUtil.amountRoundStr(x.getSettlementAmount(), 2));
            copy.setStatus(x.getOrderStatus());
            return copy;
        }).collect(Collectors.toList());
    }

    @ApiOperation(value = "用户放弃支付", notes = "用户放弃支付")
    @PostMapping("/giveUp/{orderId}")
    @AuthRequired(role = RoleType.CUSTOMER)
    public BaseResult giveUpPay(@PathVariable String orderId) {
        deviceOrderService.giveUpOrder(orderId);
        return BaseResultFactory.produceSuccess();
    }

    @ApiOperation(value = "用户订单支付", notes = "用户订单支付")
    @PostMapping("/pay")
    @AuthRequired(role = RoleType.CUSTOMER)
    public BaseResult payOrder(@RequestBody OrderPayVO orderPayVO) {
        return BaseResultFactory.produceResult(Code.SUCCESS, deviceOrderService.payOrder(orderPayVO));
    }

    @ApiOperation(value = "h5用户订单支付", notes = "h5用户订单支付")
    @PostMapping("/h5/pay")
    @AuthRequired(role = RoleType.CUSTOMER)
    public BaseResult payOrder4h5(@RequestBody OrderPayVO orderPayVO) {
        return BaseResultFactory.produceResult(Code.SUCCESS, deviceOrderService.payOrder4H5(orderPayVO));
    }

    @ApiOperation(value = "h5用户订单退款", notes = "h5用户订单退款")
    @GetMapping("/h5/pay/refund/{orderNo}")
    @AuthRequired(role = {RoleType.CUSTOMER})
    public BaseResult refund(@PathVariable String orderNo) {
        return BaseResultFactory.produceResult(Code.SUCCESS, deviceOrderService.refund(orderNo));
    }

    @ApiOperation(value = "手动启动设备", notes = "手动启动设备")
    @GetMapping("/manualStart")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult<?> manualStart(@ApiParam(value = "订单id", required = true) @RequestParam String orderId) {
        return deviceOrderService.startDevice(orderId);
    }

    @ApiOperation(value = "手动筒自洁", notes = "手动筒自洁")
    @GetMapping("/deviceSelfClean")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult<?> deviceSelfClean(@ApiParam(value = "订单id", required = true) @RequestParam String orderId) {
        return deviceOrderService.deviceSelfClean(orderId);
    }

    @ApiOperation(value = "根据订单查询设备状态", notes = "根据订单查询设备状态")
    @GetMapping(value = "/getDeviceStateByOrder")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult<DeviceStateInfoVO> getDeviceState(@ApiParam(value = "订单id", required = true) @RequestParam String orderId) {
        return BaseResultFactory.produceSuccess(deviceOrderService.getDeviceState(orderId));
    }

    @ApiOperation(value = "手动结束订单", notes = "手动结束订单")
    @GetMapping(value = "/manualComplete")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult<?> manualComplete(@ApiParam(value = "订单id", required = true) @RequestParam String orderId) {
        return deviceOrderService.manualComplete(orderId);
    }

    // 首页将会调用
    @ApiOperation(value = "运营商营收统计", notes = "运营商营收统计")
    @GetMapping(value = "/revenueStat")
    @AuthRequired(role = {RoleType.OPERATIONAL_MERCHANT,RoleType.ADMIN})
    BaseResult<OMRevenueStatisticsVO> omRevenueStatisticsVO(@ApiParam(value = "常用洗衣点") @RequestParam(required = false) String preferWashPointId) {
        OMRevenueStatisticsVO omRevenueStatisticsVO = deviceOrderService.omRevenueStatisticsVO(preferWashPointId);
        return BaseResultFactory.produceResult(Code.SUCCESS, omRevenueStatisticsVO);
    }

    @ApiOperation(value = "运营平台查询订单列表", notes = "运营平台查询订单列表")
    @GetMapping(value = "/operPlat/list")
    @AuthRequired
    BaseResult queryListForOper(Pageable pageable,
                                @ApiParam(value = "关键字") @RequestParam(required = false) String keyword,
                                @ApiParam(value = "订单状态") @RequestParam(required = false) Set<OrderStatus> status,
                                @ApiParam(value = "设备种类") @RequestParam(required = false) Set<ProductType> productType,
                                @ApiParam(value = "下单开始时间") @RequestParam(required = false) String startTime,
                                @ApiParam(value = "下单结束时间") @RequestParam(required = false) String endTime) {
        return BaseResultFactory.produceSuccess(deviceOrderService.queryListForOperPlat(pageable, keyword, status, productType, startTime, endTime));
    }

    @ApiOperation(value = "统计查询订单列表金额", notes = "统计查询订单列表金额")
    @GetMapping("/countOrderList")
    @AuthRequired
    BaseResult countOrderList(@ApiParam(value = "关键字") @RequestParam(required = false) String keyword,
                              @ApiParam(value = "订单状态") @RequestParam(required = false) Set<OrderStatus> status,
                              @ApiParam(value = "设备种类") @RequestParam(required = false) Set<ProductType> productType,
                              @ApiParam(value = "下单开始时间") @RequestParam(required = false) String startTime,
                              @ApiParam(value = "下单结束时间") @RequestParam(required = false) String endTime) {
        double amount = deviceOrderService.countOrderList(keyword, status, productType, startTime, endTime);
        return BaseResultFactory.produceResult(Code.SUCCESS, amount);
    }

    @ApiOperation(value = "运营平台导出订单列表", notes = "运营平台导出订单列表")
    @GetMapping(value = "/operPlat/export/list")
    @AuthRequired
    BaseResult exportListForOper(@ApiParam(value = "id集合") @RequestParam(required = false) Set<String> ids,
                                 @ApiParam(value = "关键字") @RequestParam(required = false) String keyword,
                                 @ApiParam(value = "订单状态") @RequestParam(required = false) Set<OrderStatus> status,
                                 @ApiParam(value = "设备种类") @RequestParam(required = false) Set<ProductType> productType,
                                 @ApiParam(value = "下单开始时间") @RequestParam(required = false) String startTime,
                                 @ApiParam(value = "下单结束时间") @RequestParam(required = false) String endTime,
                                 @ApiParam(value = "导出全部") @RequestParam(required = false) String all,
                                 HttpServletResponse response) throws IOException {

        List<ExportOrderForOperVO> exportOrderForOperVOS = deviceOrderService.exportForOperPlat(ids, keyword, status, productType, startTime, endTime, all);
        ExcelUtils.exportExcel(exportOrderForOperVOS, null, "订单信息", ExportOrderForOperVO.class, "订单导出", response);
        return BaseResultFactory.produceSuccess();
    }

    @ApiOperation(value = "空闲设备预约", notes = "空闲设备预约")
    @PostMapping(value = "/subscribe/idle")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult subscribeIdleDevice(@ApiParam(value = "orderGenerateVO", required = true) @RequestBody OrderGenerateVO orderGenerateVO) {
        return BaseResultFactory.produceSuccess(deviceOrderService.subscribeIdleDevice(orderGenerateVO));
    }

    @ApiOperation(value = "用户排队", notes = "用户排队")
    @PostMapping(value = "/joinQueue")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult joinToQueue(@ApiParam(value = "orderGenerateVO", required = true) @RequestBody OrderGenerateVO orderGenerateVO) {
        return BaseResultFactory.produceSuccess(deviceOrderService.userJoinQueue(orderGenerateVO));
    }

    @ApiOperation(value = "用户取消预约", notes = "用户取消预约")
    @PostMapping(value = "/subscribe/cancel")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult userCancelSubscribe(@ApiParam(value = "预约单id") @RequestParam String orderId) {
        deviceOrderService.userCancelSubscribe(orderId);
        return BaseResultFactory.produceSuccess();
    }

    @ApiOperation(value = "用户获取可选设备列表", notes = "用户获取可选设备列表")
    @PostMapping(value = "/picked/device/list")
    @AuthRequired(role = RoleType.CUSTOMER)
    BaseResult userQueryPickDevice(@ApiParam(value = "洗衣点id") @RequestParam String washPointId, @ApiParam(value = "设备种类") @RequestParam(required = false) ProductType productType) {
        return BaseResultFactory.produceSuccess(deviceOrderService.getUserPickDeviceList(washPointId, productType));
    }

    @ApiOperation(value = "获取未支付订单过期剩余时间", notes = "获取未支付订单过期时间")
    @GetMapping("/user/pay/leftTime")
    public BaseResult getOrderLeftPayTime(@ApiParam(value = "订单id") @RequestParam String orderId) {
        return BaseResultFactory.produceSuccess(deviceOrderService.getOrderPayLeftTime(orderId));
    }

    @ApiOperation(value = "获取用户选择剩余时间", notes = "获取用户选择时间")
    @GetMapping("/user/choice/leftTime")
    public BaseResult getUserMakeChoiceLeftTime(@ApiParam(value = "订单id") @RequestParam String orderId) {
        return BaseResultFactory.produceSuccess(deviceOrderService.getUserChoiceLeftTime(orderId));
    }

    @ApiOperation(value = "获取用户预约剩余时间", notes = "获取用户预约剩余时间")
    @GetMapping("/user/subscribe/leftTime")
    public BaseResult getUserSubscribeLeftTime(@ApiParam(value = "订单id") @RequestParam String orderId) {
        return BaseResultFactory.produceSuccess(deviceOrderService.getUserSubscribeLeftTime(orderId));
    }

    @ApiOperation(value = "获取设备排队信息", notes = "获取设备排队信息")
    @GetMapping("/device/queue/info")
    public BaseResult getUserQueueInfo(@ApiParam(value = "设备id") @RequestParam String deviceId, @ApiParam(value = "是否是预约之后") @RequestParam(defaultValue = "false") Boolean isAfterSubscribe) {
        return BaseResultFactory.produceSuccess(deviceOrderService.getUserWaitQueueInfo(deviceId, isAfterSubscribe));
    }
}
